
<template>
  <main-container headerText="团队管理 >> 团队列表">
    <div class="content" :key="showPageKey">
      <top-option>
        <div slot="left-box">
          <input-search
            lableName="手机号"
            inputValue="phone"
            :tThis="this"
            inputPlaceholder="请输入手机号"
          />

          <select-search
            lableName="级别"
            selectIdName="readeIntegral"
            :tThis="this"
            selectPlaceholder="请选择级别"
            :selectOpts="gradeOpts"
            selectWidth="150px;"
            labelWidth="80px;"
          />
        </div>
        <div slot="right-box">
          <div class="sub">
            <el-button @click="handleSearch" class="orange">查询</el-button>
          </div>
        </div>
      </top-option>

      <!-- 列表栏 -->
      <div class="list">
        <el-table
          ref="multipleTable"
          :data="tableData"
          tooltip-effect="dark"
          style="width: 100%; border-radius: 4px"
          class="tableBox"
          border
          row-key="id"
          default-expand-all
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
        >
          <el-table-column label="" >
            <template slot-scope="scope">
              
            </template>
          </el-table-column>
          <el-table-column label="当前级数(点击展开)" width="180">
            <template slot-scope="scope">
              <div
                style="cursor:pointer" 
                @click.stop="getSubUserF({ userId: scope.row.id, level: scope.row.level, item: scope.row})">
               
              {{ scope.row.level || "-" }}
              </div>
            </template>
          </el-table-column>
            <el-table-column label="用户昵称" width="undefined">
            <template slot-scope="scope">
               {{ scope.row.nickName || "-" }}
            </template>
          </el-table-column>
          <el-table-column label="手机号" width="undefined">
            <template slot-scope="scope">
              {{ scope.row.phone || "-" }}
            </template>
          </el-table-column>
          <el-table-column label="会员级别" width="undefined">
            <template slot-scope="scope">
              {{ scope.row.grade || "-" }}
            </template>
          </el-table-column>
          <el-table-column label="创客级别" width="undefined">
            <template slot-scope="scope">
              {{ scope.row.guestName || "-" }}
            </template>
          </el-table-column>
          <el-table-column label="推荐人" width="undefined">
            <template slot-scope="scope">
              {{ scope.row.recommendPhone || "-" }}
            </template>
          </el-table-column>
          <el-table-column label="团队人数" width="undefined">
            <template slot-scope="scope">
              {{ scope.row.teamSize || "-" }}
            </template>
          </el-table-column>
          <el-table-column label="团队业绩" width="undefined">
            <template slot-scope="scope">
              {{ scope.row.teamPerformance || "-" }}
            </template>
          </el-table-column>

          <el-table-column label="操作" width="90">
            <template slot-scope="scope">
              <el-button
                @click="handleView"
                type="primary"
                :data-id="scope.row.id"
                size="small"
                >查看</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!-- 分页 -->
      <div class="paging">
        <div class="block">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPageIdx"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="onePageSize"
            layout="total, prev, pager, next, jumper"
            :total="pageCount"
          ></el-pagination>
        </div>

        <div class="confirm-btn">
          <el-button class="paging-btn" @click="handleEnter" size="small"
            >确定</el-button
          >
        </div>
      </div>
    </div>
  </main-container>
</template>

  <script>
import jhTools from "@/utils/jhTools"; //工具函数
import API from "@/utils/api_config.js"; //引入api

import main_container from "@/components/main_container";
import top_option from "@/components/subCon/topOption";
import input_search from "@/components/subCon/inputSearch";
import select_search from "@/components/subCon/selectSearch";
import date_search from "@/components/subCon/dateSearch";

export default {
  components: {
    "main-container": main_container,
    "top-option": top_option,
    "input-search": input_search,
    "select-search": select_search,
    "date-search": date_search,
  },
  props: {},
  data() {
    return {
      //列表
      tableData: [],
      multipleSelection: [],
      showPageKey: 101,
      //分页
      currentPageIdx: 1, //当前页与跳转框的初始值
      pageCount: 1, //总条数
      onePageSize: 10, //每页的条数

      formData: {
        phone: null,
        readeIntegral: null,
      },

      gradeOpts: [
        { value: "1", label: "普粉" },
        { value: "2", label: "铁粉" },
        { value: "3", label: "超粉" },
        { value: "4", label: "V1" },
        { value: "5", label: "V2" },
        { value: "6", label: "V3" },
        { value: "7", label: "V4" },
        { value: "8", label: "V5" },
        { value: "9", label: "V6" },
        { value: "10", label: "V7" },
        { value: "", label: "全部" },
      ],

      allMethods: "",
    };
  },
  mounted() {
    this.allMethods = this.getAllMethods();

    this.initRequest();

    this.getInitData();
  },
  methods: {
    //查看
    handleView(e) {
      this.allMethods.handleView(e);
    },

    //查询
    handleSearch() {
      this.allMethods.handleSearch();
    },

    //获取树形节点子成员
    getSubUserF ( {userId, level, item} ){
      this.tools.basePost ({
        url: this.api.team_m.searchTeamList,
        params: { userId: userId },
        success: (res) => {
          res.data.team.forEach((item,index)=> {
            item.level = (level + 1);
          })
          item.children = res.data.team;
          this.showPageKey = Math.random().toFixed(4)
        },
      })
    },

    /* 方法抽离集合 */
    getAllMethods() {
      var _this = this;
      return {
        //查看
        handleView(e) {
          var { id } = e.currentTarget.dataset;
          _this.$router.push({
            path: "/team_m_team_detail_table",
            query: { id },
          });
        },

        //查询
        handleSearch() {
          var { phone, readeIntegral } = _this.formData;
          _this.LingChuang_request.handleSearch({
            phone,
            readeIntegral,
            pageIndex: _this.currentPageIdx,
            pageSize: _this.onePageSize,
          });
        },
      };
    },

    //表格默认函数
    //初始化
    initRequest() {
      this.LingChuang_request = jhTools.LingChuang_request({
        this: this,
        pageUrl: API.team_m.searchTeamList,
        searchUrl: API.team_m.searchTeamList,
        searchData: {},
      });
      // console.log(this.LingChuang_request);
    },

    //加载数据
    getInitData: function () {
      var _this = this;
      this.LingChuang_request.getInitData(
        {
          pageIndex: this.currentPageIdx,
          pageSize: this.onePageSize,

          userId: null, //请求
        },
        function (res) {
          //初始格式化数据
        },
        function (res) {
          //配置信息
          res.data.team.forEach((item,index)=> {
            item.index = index + 1;
            item.level = 1;
          })
          _this.tableData = res.data.team;
        }
      );
    },
    //格式化数据
    formatData() {
      this.LingChuang_request.formatData();
    },
    //格式化页面
    formatPaging(res) {
      this.LingChuang_request.formatPaging(res);
    },
    //页数跳转
    handleSizeChange(val) {
      this.LingChuang_request.handleSizeChange(val);
    },
    //页面点击跳转
    handleCurrentChange(val) {
      this.LingChuang_request.handleCurrentChange(val);
    },
    //enter跳转
    handleEnter() {
      this.LingChuang_request.getPagingData(
        this.currentPageIdx,
        this.onePageSize
      );
    },
    //分页数据
    getPagingData(pageIndex, pageSize) {
      this.LingChuang_request.handleEnter(pageIndex, pageSize);
    },
    //列表勾选1
    toggleSelection(rows) {
      this.LingChuang_request.toggleSelection(rows);
    },
    //列表勾选2
    handleSelectionChange(val) {
      this.LingChuang_request.handleSelectionChange(val);
    },
    //表格默认函数

    /* 图片预览 */
    previewImgF({ imgUrl }) {
      this.tools.touchGEvent({
        eName: "previewImg",
        imgUrl,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
// @import '~styles/mixins.scss';
// @import '~styles/variables.scss';

//隐藏样式类
.hidden {
  display: none !important;
}
</style>
